<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<html class="h100b">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<script type="text/javascript" src="${path}/ajax.do?managerName=qiangsSeepManager"></script>
<script type="text/javascript">
    $(document).ready(function() {
		$("#tree").tree({
			//onClick : clk,
			//beforeDrag : beforeDrag,
			//beforeDrop : beforeDrop,
			//managerName : "qiangsSeepManager",
			//managerMethod : "getTreeDate",
			idKey : "id",
			pIdKey : "pid",
			nameKey : "name",
			enableCheck : true,//6
			enableEdit : false,
			enableRename : false,
			enableRemove : false,
			/*asyncParam : {
				orgname : '组织'
			},*/
			nodeHandler : function(n) {//11
				n.open = n.data.open;
				n.checked = n.data.checked;
			},
			render : function(name, data) {//14
				return name;
			}
        });
 /**
        function clk(e, treeId, node) {
          alert($.toJSON(node.data));
          //node.children[0].data 取第0个子节点的数据对象
        }
 
        function beforeDrag(treeId, treeNodes) {
          if (treeNodes[0].drag === false) {
            return false;
          }
          return true;
        }
        function beforeDrop(treeId, treeNodes, targetNode, moveType) {
          return targetNode ? targetNode.drop !== false : true;
        }
 
        $("#selectedBtn").click(function() {
          var nodes = $("#tree").treeObj().getSelectedNodes();//15
          alert($.toJSON(nodes));
        });
        $("#checkedBtn").click(function() {
          var nodes = $("#tree").treeObj().getCheckedNodes();//16
          alert($.toJSON(nodes));
        });
 
        $("#asyncBtn").click(function() {
          $("#tree").treeObj().reAsyncChildNodes(null, "refresh");//17
        });
		*/
		$("#selectAll").change(function (){
			var nodes = $("#tree").treeObj().getNodes();
			if($("#selectAll").attr('checked')){
				selectAll(nodes, true);
			} else {
				selectAll(nodes, false);
			}
			$("#tree").treeObj().refresh();
		});
    });
	
    var isTop = ${isTop};
	function selectAll(nodes, isSelect){
		for(var i = 0; i < nodes.length; i++){
			nodes[i].checked = isSelect;
			if(nodes[i].isParent){
				nodes[i].open = isSelect;
				selectAll(nodes[i].children, isSelect);
			}
		}
	}
	function OK(){
		var data = "";
		var show = "";
		var nodes = $("#tree").treeObj().getCheckedNodes();
		for(var i = 0; i < nodes.length; i++){
			if((isTop == 0 && nodes[i].data.isBotton) 
				|| (isTop == 1 && nodes[i].data.isTop)){
				if("" == data){
					data += nodes[i].id;
					show += nodes[i].name;
				} else {
					data += "," + nodes[i].id;
					show += "," + nodes[i].name;
				}
			}
		}
		return {'data': data, 'show': show};
	}
</script>
</head>
<body>
<div style="height: 25px;padding-left: 10px;font-size: 12px;padding-top: 10px;"><input type="checkbox" name="selectAll" id="selectAll" />全选</div>
<div id="tree"></div>
</body>
</html>